﻿using System;
using System.Collections.Generic;
using SymbolIntegration.core.Helpers;

namespace SymbolIntegration.core.Expressions.Functions
{
    public class TgFunction : FuncExpression
    {
        internal static FuncExpression ParseItself(string expression, int position, int size)
        {
            var result = new TgFunction();
            result.InnerParseItself(expression, position, size);
            return result;
        }

        public TgFunction(Expression expr):base(expr)
        {

        }

        protected TgFunction()
        {

        }

        public override Expression Clone()
        {
            var clone = new TgFunction(m_Argument);
            InnerCopy(clone);
            return clone;
        }

        protected internal override Expression IntegrateAsDependentFromVar(string variable, IIntegrator integrator)
        {
            return integrator.TryIntegrateMultipliers(new List<Expression>() {this}, variable);
        }

        public override FunctionType FunctionType
        {
            get { return FunctionType.Tg; }
        }

        protected override string GetFunctionName()
        {
            return "tg";
        }

        protected override ConstantExpression Apply(double constant)
        {
            return new ConstantExpression(Math.Tan(constant));
        }

        protected override Expression InnerFuncDifferentiate(string argument)
        {
            return new ConstantExpression(1) / ( new ConstantExpression(1) + m_Argument*m_Argument);
        }
    }
}